import request from '@/utils/request';
import type { HttpResult, PageResult } from '@/api';
import type {
  AddSysPermission,
  SysPermission,
  EditSysPermission,
  SysPermissionQueryData
} from './model/index.js';

// 新增
export const add = async (data: AddSysPermission): Promise<HttpResult<SysPermission>> => {
  const res = await request.post<HttpResult<SysPermission>>(
    '/system/sysPermission/add',
    data,
  );
  return res.data;
};

// 删除
export const del = async (ids: string[]): Promise<HttpResult<boolean>> => {
  const res = await request.post<HttpResult<boolean>>(
    `/system/sysPermission/delete`,
    ids
  );
  return res.data;
};

// 修改
export const edit = async (data: EditSysPermission): Promise<HttpResult<SysPermission>> => {
  const res = await request.post<HttpResult<SysPermission>>(
    '/system/sysPermission/edit',
    data,
  );
  return res.data;
};

// 查询单个权限详情
export const query = async (id: number): Promise<HttpResult<SysPermission>> => {
  const res = await request.post<HttpResult<SysPermission>>(
    `/system/sysPermission/query?id=${id}`,
  );
  return res.data;
};

// 查询分页
export const queryPage = async (data: SysPermissionQueryData): Promise<HttpResult<PageResult<SysPermission[]>>> => {
  const res = await request.post<HttpResult<PageResult<SysPermission[]>>>(
    `/system/sysPermission/queryPage`,
    data
  );
  return res.data;
};




